#ifndef KEYMANAGER_H
#define KEYMANAGER_H

#include "ECCOperator.h"

#include <string>

//所有的密钥应该都是现在这里面管理的吧，因此后面需要的就是计算会话密钥的
class keyManager
{
public:
    static keyManager &instance()
    {
        static keyManager instance;
        return instance;
    }

    keyManager(const keyManager &) = delete;
    keyManager operator=(const keyManager &) = delete;

    bool initializeKeys();
    void setKeys(std::shared_ptr<BIGNUM> bnPrikey,
                 std::shared_ptr<EC_POINT> ec_pubKey,
                 std::shared_ptr<EVP_PKEY> evp_SK,
                 std::shared_ptr<EVP_PKEY> evp_PK);
    std::shared_ptr<EC_POINT> getPubkey();
    std::shared_ptr<BIGNUM> getPriKey();
    std::shared_ptr<unsigned char> getSalt(); //这里的目的是程序运行时所有模块共用一个盐值来计算会话密钥
    std::shared_ptr<EC_POINT> getCAPubKey();
    void setSymmKey(const std::vector<unsigned char> &symmKey);
    bool getSymmKeyIsSeted();
    std::vector<unsigned char> getSymmKey();

private:
    keyManager();
    ECCOperator m_ecc;
    std::shared_ptr<EVP_PKEY> evp_pubKey;
    std::shared_ptr<EVP_PKEY> evp_prikey;
    std::shared_ptr<BIGNUM> bn_priKey;
    std::shared_ptr<EC_POINT> ec_point_pubKey;
    std::shared_ptr<EC_POINT> ca_ecpoint_pubKey;
    std::shared_ptr<unsigned char> m_salt;
    bool SymmKeyIsSeted;
    std::vector<unsigned char> symmKey_vector;
};

#endif // KEYMANAGER_H
